@echo off

if not exist import  mkdir  import
if not exist importdec  mkdir  importdec


if not exist extracted\*.FTCX   call  wiso\eFont.bat

if exist ..\import\font\0218.FTCX   copy  /Y  ..\import\font\0218.FTCX   import\0218.FTCX >NUL


if not exist extdec\*.g*        call  wiso\eGraphic.bat

FOR %%i IN (..\import\ghelp\*.bmp) DO (
    if exist extdec\%%~ni.gwh   ffxgwh -i    extdec\%%~ni.gwh   %%i   importdec\%%~ni.gwh
)

rem extension may be pressent or missing
FOR %%i IN (extdec\0240*) DO if exist ..\import\graphic\0240.bmp   ffxgnop -i 0x9A1D0  %%i  ..\import\graphic\0240.bmp  importdec\%%~nxi
FOR %%i IN (extdec\0252*) DO if exist ..\import\graphic\0240.bmp   ffxgnop -i 0x9A1D0  %%i  ..\import\graphic\0240.bmp  importdec\%%~nxi


if exist ..\import\graphic\2986_?.bmp  FOR %%i IN (extdec\2986*) DO (
    rem multiple import to 1 file
    copy /Y  %%i  importdec\%%~nxi  >NUL
    if exist ..\import\graphic\2986_0.bmp   ffxgnop -i 0x25F00  importdec\%%~nxi  ..\import\graphic\2986_0.bmp
    if exist ..\import\graphic\2986_1.bmp   ffxgnop -i 0x2DF00  importdec\%%~nxi  ..\import\graphic\2986_1.bmp
    if exist ..\import\graphic\2986_2.bmp   ffxgnop -i 0x35F00  importdec\%%~nxi  ..\import\graphic\2986_2.bmp
    if exist ..\import\graphic\2986_3.bmp   ffxgnop -i 0x3DF00  importdec\%%~nxi  ..\import\graphic\2986_3.bmp
    if exist ..\import\graphic\2986_4.bmp   ffxgnop -i 0x45F00  importdec\%%~nxi  ..\import\graphic\2986_4.bmp
    if exist ..\import\graphic\2986_5.bmp   ffxgnop -i 0x4DF00  importdec\%%~nxi  ..\import\graphic\2986_5.bmp
    if exist ..\import\graphic\2986_6.bmp   ffxgnop -i 0x55F00  importdec\%%~nxi  ..\import\graphic\2986_6.bmp
)
rem same BMP files as above, but to 2945
if exist ..\import\graphic\2986_?.bmp  FOR %%i IN (extdec\2945*) DO (
    rem multiple import to 1 file
    copy /Y  %%i  importdec\%%~nxi  >NUL
    if exist ..\import\graphic\2986_0.bmp   ffxgnop -i 0x22B80  importdec\%%~nxi  ..\import\graphic\2986_0.bmp
    if exist ..\import\graphic\2986_1.bmp   ffxgnop -i 0x2AB80  importdec\%%~nxi  ..\import\graphic\2986_1.bmp
    if exist ..\import\graphic\2986_2.bmp   ffxgnop -i 0x32B80  importdec\%%~nxi  ..\import\graphic\2986_2.bmp
    if exist ..\import\graphic\2986_3.bmp   ffxgnop -i 0x3AB80  importdec\%%~nxi  ..\import\graphic\2986_3.bmp
    if exist ..\import\graphic\2986_4.bmp   ffxgnop -i 0x42B80  importdec\%%~nxi  ..\import\graphic\2986_4.bmp
    if exist ..\import\graphic\2986_5.bmp   ffxgnop -i 0x4AB80  importdec\%%~nxi  ..\import\graphic\2986_5.bmp
)


if exist ..\import\graphic\0225.bmp  (
    if not exist ..\import\graphic\m0225.bmp   ffxgnop -c  ..\import\graphic\0225.bmp  import\0225.gnop
    if     exist ..\import\graphic\m0225.bmp   ffxgnop -m  extracted\0225.gnop   ..\import\graphic\0225.bmp  ..\import\graphic\m0225.bmp  import\0225.gnop
)
if exist ..\import\graphic\0226.bmp  (
    if not exist ..\import\graphic\m0226.bmp   ffxgnop -c  ..\import\graphic\0226.bmp  import\0226.gnop
    if     exist ..\import\graphic\m0226.bmp   ffxgnop -m  extracted\0226.gnop   ..\import\graphic\0226.bmp  ..\import\graphic\m0226.bmp  import\0226.gnop
)
if exist ..\import\graphic\0230.bmp  (
    if not exist ..\import\graphic\m0230.bmp   ffxgnop -c  ..\import\graphic\0230.bmp  import\0230.gnop
    if     exist ..\import\graphic\m0230.bmp   ffxgnop -m  extracted\0230.gnop   ..\import\graphic\0230.bmp  ..\import\graphic\m0230.bmp  import\0230.gnop
)
rem multiple mask files
if not exist ..\import\graphic\m0229*   if exist ..\import\graphic\0229.bmp  ffxgnop -c  ..\import\graphic\0229.bmp  import\0229.gnop
if     exist ..\import\graphic\m0229*   if exist ..\import\graphic\0229*     copy /Y  extracted\0229.gnop   import\0229.gnop  >NUL
if     exist ..\import\graphic\m0229*   if exist ..\import\graphic\0229*     FOR %%i IN (..\import\graphic\0229*.bmp) DO (
    if     exist ..\import\graphic\m%%~ni.bmp   ffxgnop -m  import\0229.gnop   %%i  ..\import\graphic\m%%~ni.bmp
    if not exist ..\import\graphic\m%%~ni.bmp   echo WARN: ignoring %%i - dont have mask file, but mask files m0229* exist
)


if exist ..\import\graphic\0175.bmp   ffxgnop  -i 0x420  extdec\0175.gp  ..\import\graphic\0175.bmp  importdec\0175.gp
if exist ..\import\graphic\0181.bmp   ffxgnop  -i 0x420  extdec\0181.gp  ..\import\graphic\0181.bmp  importdec\0181.gp
if exist ..\import\graphic\0178_?.bmp (
    rem multiple import to 1 file
    copy /Y  extdec\0178.gp   importdec\0178.gp  >NUL
    if exist ..\import\graphic\0178_0.bmp   ffxgnop  -i 0x450    importdec\0178.gp  ..\import\graphic\0178_0.bmp
    if exist ..\import\graphic\0178_1.bmp   ffxgnop  -i 0x40850  importdec\0178.gp  ..\import\graphic\0178_1.bmp
    if exist ..\import\graphic\0178_2.bmp   ffxgnop  -i 0x80C50  importdec\0178.gp  ..\import\graphic\0178_2.bmp
    if exist ..\import\graphic\0178_3.bmp   ffxgnop  -i 0x91050  importdec\0178.gp  ..\import\graphic\0178_3.bmp
)


rem if exist ..\import\graphic\3738.bmp   ffxgnop  -i 0x72D10  extdec\3738.map  ..\import\graphic\3738.bmp  importdec\3738.map
rem if exist ..\import\graphic\3740.bmp   ffxgnop  -i 0x1B0    extdec\3740.map  ..\import\graphic\3740.bmp  importdec\3740.map
rem workaround due bad compression with ffxtool_v03 at end of map file
rem after file end write bytes, which should be uncompressed, or compressed by RLE
rem if exist importdec\3738.map   fcopy -idx importdec\3738.map  1677072   FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
rem if exist importdec\3740.map   fcopy -idx importdec\3740.map  2085840   FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

if exist ..\import\graphic\3738.bmp   ffxmap -i3  extdec\3738.map  ..\import\graphic\3738.bmp  importdec\3738.map
if exist ..\import\graphic\3740.bmp   ffxmap -i0  extdec\3740.map  ..\import\graphic\3740.bmp  importdec\3740.map

if not exist itemp  mkdir itemp
if exist ..\import\gworld\*.bmp (
    call dupcopy_3650.bat  ..\import\gworld\   itemp\
    ffxmap  -i      extdec\3650.map      ..\import\gworld\3650_    importdec\3650.map
    ffxmap  -i      importdec\3650.map   itemp\3650_
    rem 3640 is "same"
    ffxmap  -i      extdec\3640.map      ..\import\gworld\3650_    importdec\3640.map
    ffxmap  -i      importdec\3640.map   itemp\3650_
)
rem same as above, but palette import variant (can be both at once)
if exist ..\import\gworld_p\*.bmp (
    rem try import to previously created importdec\3650.map
    if not exist importdec\3650.map      copy  extdec\3650.map  importdec\3650.map >NUL
    if not exist importdec\3640.map      copy  extdec\3640.map  importdec\3640.map >NUL
    rem create those duples for palette import with "p_" at start
    call dupcopy_3650.bat  ..\import\gworld_p\   itemp\p_
    ffxmap  -ip     importdec\3650.map   ..\import\gworld_p\3650_
    ffxmap  -ip     importdec\3650.map   itemp\p_3650_
    rem 3640 is "same"
    ffxmap  -ip     importdec\3640.map   ..\import\gworld_p\3650_
    ffxmap  -ip     importdec\3640.map   itemp\p_3650_
)


